﻿@* Generator: Template
    GeneratePrettyNames : true *@
@functions{
    public NFinal.Compile.SqlTemplate.Model.QueryRow Model { get; set; }
}
#region	var @{@Model.varName}; 选取一行
			@if(Model.hasGenericType){
			if(Model.isDeclaration){
			@:@{@Model.type} @{@Model.varName}=new @{@Model.type}();
			}
			}else{
			@:var @{@Model.varName} = new __@{@Model.functionName}_@{@Model.varName}__();
            }
			var __@{@Model.functionName}_@{@Model.varName}_command__ = new System.Data.SqlClient.SqlCommand("@{@Model.sql}", @{@Model.connectionVarName});
			@if(Model.isTransaction){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Transaction=@{@Model.transactionVarName};
			}
			@if(Model.sqlVarParameters.Count>0){
			@:var __@{@Model.functionName}_@{@Model.varName}_parameters__=new System.Data.SqlClient.SqlParameter[@{@Model.sqlVarParameters.Count}];
			}
			@{int i=0;}
			@foreach(var sqlVarParameter in Model.sqlVarParameters){
			if(sqlVarParameter.field.length>0){
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new System.Data.SqlClient.SqlParameter("@@@{@sqlVarParameter.name}",System.Data.SqlDbType.@{@sqlVarParameter.field.dbType},@{@sqlVarParameter.field.length});
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName};
			}else{
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new System.Data.SqlClient.SqlParameter("@@@{@sqlVarParameter.name}",System.Data.SqlDbType.@{@sqlVarParameter.field.dbType});
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName};
			}
			i++;
			}
			@if(Model.sqlVarParameters.Count>0){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Parameters.AddRange(__@{@Model.functionName}_@{@Model.varName}_parameters__);
			}
			var __@{@Model.functionName}_@{@Model.varName}_reader__= __@{@Model.functionName}_@{@Model.varName}_command__.ExecuteReader();
			if (__@{@Model.functionName}_@{@Model.varName}_reader__.HasRows)
			{
				__@{@Model.functionName}_@{@Model.varName}_reader__.Read();
				@if(Model.hasGenericType){
				@:@{@Model.varName} = new @{@Model.type}();
				}else{
				@:@{@Model.varName} = new __@{@Model.functionName}_@{@Model.varName}__();
				}
				@{i=0;}
				@foreach(var field in Model.fields){
				if(field.allowNull){
					if(field.isValueType){
					@:if(!__@{@Model.functionName}_@{@Model.varName}_reader__.IsDBNull(@i)){@{@Model.varName}.@{@field.structFieldName} =@{@field.GetMethodConvert} __@{@Model.functionName}_@{@Model.varName}_reader__.@{@field.GetMethodName}(@i)@{@field.GetMethodValue};}
					}else{
					@:@{@Model.varName}.@{@field.structFieldName} =__@{@Model.functionName}_@{@Model.varName}_reader__.IsDBNull(@i)?null:@{@field.GetMethodConvert} __@{@Model.functionName}_@{@Model.varName}_reader__.@{@field.GetMethodName}(@i)@{@field.GetMethodValue};
					}
					}else{
					@:@{@Model.varName}.@{@field.structFieldName} =@{@field.GetMethodConvert} __@{@Model.functionName}_@{@Model.varName}_reader__.@{@field.GetMethodName}(@i)@{@field.GetMethodValue};
					}
				i++;
				}
			}
			else
			{
				@{@Model.varName} = null;
			}
			__@{@Model.functionName}_@{@Model.varName}_reader__.Dispose();
			__@{@Model.functionName}_@{@Model.varName}_command__.Dispose();
			#endregion
			